<?php
namespace Admin\Model;
use Common\Model\CommonModel;
//绘画作品
class ShopModel extends  CommonModel{

	//自动验证
	protected $_validate = array(
		//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
		array('name', 'require', '名称不能为空！', 1, 'regex', 3),
		array('address', 'require', '标识符不能为空！', 1, 'regex', 3),


	);


	public function _after_update() {
		return true;
	}

	public function _after_insert() {
		parent::_after_insert();
		$this->data_cache();
	}
	//删除操作时删除缓存
	public function _after_delete() {
		parent::_after_delete();
		$this->data_cache();
	}


	public function data_cache(){


		$data=$this->where("status = 1")->select();

		foreach ($data as $k=>$v){

			$result[$v[id]]=$v;

		}

		F("Shop",$result);










	}


	public function update_status($room_id){




		$num=D("RoomLog")->where(array("room_id"=>$room_id,"status"=>0))->count();

		$room_changenum=F("Room")[$room_id][changenum];
		$room_maxnum=F("Room")[$room_id][maxnum];


		$v["id"]=$room_id;
		if($num>=$room_changenum){

			$v["status"]=0;

		}
		elseif($num==0){

			$v["status"]=1;
		}
		else{

			$v["status"]=2;
		}


		if($num<$room_maxnum){

			$v["isru"]=1;

		}

		else{

			$v["isru"]=0;
		}




		$this->save($v);

		return $v["status"];



	}



}